package com.hy.video.monitor.annotation;

import com.hy.video.monitor.util.Constants;
import org.springframework.security.access.prepost.PreAuthorize;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * 必须为当前登录认证过的用户或者具有修改用户信息权限或者管理员角色
 * hasRole
 * hasAnyRole('ADMIN','USER') 书写不需要前缀，默认会加上
 * hasAuthority
 * hasAnyAuthority('ROLE_ADMIN', 'ROLE_USER') 书写需要加前缀
 */
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("authentication.name == #user.username or " +
    "hasAnyAuthority('" + Constants.ROLE_ADMIN + "', '" + Constants.AUTHORITY_USER_UPDATE + "')")
public @interface RoleAdminOrSelfWithUserParam {
}
